from django.utils.decorators import method_decorator

from gis.admin.decorators import require_login, check_permission
from gis.common import track_logging
from gis.common.django_ext.decorators import validate_parameters
from gis.common.django_ext.views import BaseView
from itpay.core.sys import conf_service
from itpay.server_admin.view.sys.conf_forms import UpdateOrderCommentSchema

_LOGGER = track_logging.getLogger(__name__)


class OrderCommentConfView(BaseView):
    @method_decorator(require_login)
    @method_decorator(check_permission('features_config_get'))
    def get(self, request):
        return dict(can_comment=conf_service.get_order_can_comment())

    @method_decorator(require_login)
    @method_decorator(check_permission('features_config_update'))
    @method_decorator(validate_parameters(UpdateOrderCommentSchema))
    def put(self, request, cleaned_data):
        conf_service.set_order_can_comment(**cleaned_data)
